package com.coupon.dal.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.coupon.dao.BaseEntity;

@Entity
@Table(name = "coupon")
@Cache(region = "couponRegion", usage = CacheConcurrencyStrategy.READ_WRITE)
public class Coupon extends BaseEntity {

	private Long id;

	private String dealCompanyId;

	private String dealCompanyName;

	private Integer dealDiscount;

	private Double originalPrice;

	private Double dealPrice;

	private String dealDescription;

	private Integer dealAreaId; // todo - enum [Mercaz/Darom]

	private Date expirationDate;

	private int joinedUsers;

	private String freeText;

	private String ownerId;

	private String image;

	private List<User> users;
	
	private boolean  selected;
	
	
	@Id
	@GeneratedValue(generator = "hibernateSequence")
	@SequenceGenerator(name = "hibernateSequence", sequenceName = "HIBERNATE_SEQUENCE")
	@Column(name = "COUPON_ID", nullable = false, length = 12)
	public Long getId() {
		return id;
	}
	
	

	public void setId(Long id) {
		this.id = id;
	}



	@ManyToMany(mappedBy = "coupons")
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@Column
	public String getDealCompanyId() {
		return dealCompanyId;
	}

	public void setDealCompanyId(String dealCompanyId) {
		this.dealCompanyId = dealCompanyId;
	}

	@Column
	public String getDealCompanyName() {
		return dealCompanyName;
	}

	public void setDealCompanyName(String dealCompanyName) {
		this.dealCompanyName = dealCompanyName;
	}

	@Column
	public Integer getDealDiscount() {
		return dealDiscount;
	}

	public void setDealDiscount(Integer dealDiscount) {
		this.dealDiscount = dealDiscount;
	}

	@Column
	public Double getOriginalPrice() {
		return originalPrice;
	}

	public void setOriginalPrice(Double originalPrice) {
		this.originalPrice = originalPrice;
	}

	@Column
	public Double getDealPrice() {
		return dealPrice;
	}

	public void setDealPrice(Double dealPrice) {
		this.dealPrice = dealPrice;
	}

	@Column
	public String getDealDescription() {
		return dealDescription;
	}

	public void setDealDescription(String dealDescription) {
		this.dealDescription = dealDescription;
	}

	@Column
	public Integer getDealAreaId() {
		return dealAreaId;
	}

	public void setDealAreaId(Integer dealAreaId) {
		this.dealAreaId = dealAreaId;
	}

	@Column
	public Date getExpirationDate() {
		return expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	@Column
	public int getJoinedUsers() {
		return joinedUsers;
	}

	public void setJoinedUsers(int joinedUsers) {
		this.joinedUsers = joinedUsers;
	}

	@Column
	public String getFreeText() {
		return freeText;
	}

	public void setFreeText(String freeText) {
		this.freeText = freeText;
	}

	@Column
	public String getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(String ownerId) {
		this.ownerId = ownerId;
	}

	@Column
	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	

	@Override
	public int hashCode() {
		return (id != null ? id.hashCode() : 0);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Coupon that = (Coupon) o;

		if (id != null ? !id.equals(that.id) : that.id != null)
			return false;

		return true;
	}


	@Transient
	public boolean isSelected() {
		return selected;
	}



	public void setSelected(boolean selected) {
		this.selected = selected;
	}



	
	



	
	
	/*
	 * private User user;
	 * 
	 * @ManyToOne
	 * 
	 * @JoinColumns( { @JoinColumn(name = "USER_ID", referencedColumnName =
	 * "USER_ID", nullable = false) }) public User getUser() { return user; }
	 * 
	 * public void setUser(User user) { this.user = user; }
	 */

}
